# Customized deploy.rb
set :application, "dict"

set :repository, "https://ror-dict.googlecode.com/svn/branches/stable/"
set :scm_username, 'cristianrasch'
set :scm_password, proc{Capistrano::CLI.password_prompt('SVN pass:' )}

role :web, "dict.server"
role :app, "dict.server"
role :db, "dict.server", :primary => true

set :user, "cristian"
ssh_options[:port] = 25836

set :deploy_via, :export
set :deploy_to, "/home/#{user}/public_html/#{application}"

desc "Symlink the database config file from shared
      directory to current release directory."
task :symlink_database_yml do
  run "ln -nsf #{shared_path}/config/database.yml
       #{release_path}/config/database.yml"
end
after 'deploy:update_code' , 'symlink_database_yml'

desc "Symlink the app config file from shared
      directory to current release directory."
task :symlink_app_config_yml do
  run "ln -nsf #{shared_path}/config/app_config.yml
       #{release_path}/config/app_config.yml"
end
after 'deploy:update_code' , 'symlink_app_config_yml'

desc "Symlink the backgroundrb config file from shared
      directory to current release directory."
task :symlink_backgroundrb_config_yml do
  run "ln -nsf #{shared_path}/config/backgroundrb.yml
       #{release_path}/config/backgroundrb.yml"
end
after 'deploy:update_code' , 'symlink_backgroundrb_config_yml'

after 'deploy:update_code' , 'deploy:migrate'

namespace(:deploy) do
  desc "Restart mongrels & backgroundrb servers"
  task :restart do
    stop_backgroundrb
    restart_mongrel_cluster
	  start_backgroundrb
  end
end

desc "Stop the mongrel cluster"
task :stop_mongrel_cluster , :roles => :app do
  run "mongrel_cluster_ctl stop"
end

desc "Start the mongrel cluster"
task :start_mongrel_cluster , :roles => :app do
  run "mongrel_cluster_ctl start"
end

desc "Restart the mongrel cluster"
task :restart_mongrel_cluster , :roles => :app do
  run "mongrel_cluster_ctl restart"
end

desc "Stop the backgroundrb server"
task :stop_backgroundrb , :roles => :app do
  sudo "#{current_path}/script/backgroundrb stop"
end

desc "Start the backgroundrb server"
task :start_backgroundrb , :roles => :app do
  sudo "#{current_path}/script/backgroundrb start -e production > /dev/null 2>&1"
end

desc "Start the backgroundrb server"
task :restart_backgroundrb, :roles => :app do
  stop_backgroundrb
  start_backgroundrb
end

task :tail_log, :roles => :app do
  stream "tail -f #{shared_path}/log/production.log"
end

#Only the Contents of log and public/system Will Be Kept Between
#Deployments

#after 'deploy:update_code' , 'deploy:link_images'
#namespace(:deploy) do
#  task :link_images do
#    run <<-CMD
#      cd #{release_path} &&
#      ln -nfs #{shared_path}/avatars #{release_path}/public/avatars
#    CMD
#  end
#end
